      implicit undefined (a-z)
      integer fgetc, ctoi
      integer length, upcnt, io, io2, eofflg, blank
      character cnum(400), inp(100), clbl8(8), ch1r
23000 continue
      eofflg = fgetc( 5, ch1r)
      if(eofflg .eq.  -1)then
      write ( 0, '("EOF in first line of APPC")')
      stop
      endif
      call fputc( 6, ch1r)
23001 if(.not.(ch1r .eq. char(10)))goto 23000
23002 continue
23005 continue
      do23008 io2 = 1, 6 
      eofflg = fgetc( 5, inp(io2))
      if(eofflg .eq.  -1)then
      write ( 0, 970) upcnt
970   format ('appc EOF after', i10, 'update lines; end')
      stop
      endif
23008 continue
23009 continue
      upcnt = upcnt + 1
      io2 = 1 
      length = ctoi(inp, io2)
      do23012 io2 = 1, 8
      eofflg = fgetc( 5, clbl8(io2))
23012 continue
23013 continue
      do23014 io2 = 1, 2
      eofflg = fgetc( 5, ch1r)
23014 continue
23015 continue
      io2=1
23016 if(.not.(io2.le.length))goto 23018
      eofflg = fgetc( 5, cnum(io2))
      if(cnum(io2) .eq. char(10))then
      io2 = io2 - 1
      do23021 io = 1, 16
      eofflg = fgetc( 5, ch1r)
23021 continue
23022 continue
      endif
23017 io2=io2+1
      goto 23016
23018 continue
      eofflg = fgetc( 5, ch1r)
      do23023 io = 1, length 
      if((io.lt.length).and.((mod(length-io,60).eq.59).or.(io.eq.1)))then
      if(io .eq. 1)then
      call putdec( 6, length, 4)
      call fputc( 6,  " ")
      do23029 io2 = 1, 3
      call fputc( 6, clbl8(io2))
23029 continue
23030 continue
      blank = 0
23031 if(clbl8(4 + blank) .eq.  " ")then
      blank = blank + 1
      goto 23031
      endif
23032 continue
      do23033 io2 = 4 + blank, 8
      call fputc( 6, clbl8(io2))
23033 continue
23034 continue
      do23035 io2 = 1, 4 + blank
      call fputc( 6,  " ")
23035 continue
23036 continue
      if((length .gt. 60) .and. (mod(length, 60) .gt. 0))then
      do23039 io2 = 1, 60 - mod(length, 60) 
      call fputc( 6,  " ")
      if(mod(io2, 10) .eq. 0)then
      call fputc( 6,  " ")
      endif
23039 continue
23040 continue
      endif
      else
      do23043 io2 = 1, 17
      call fputc( 6,  " ")
23043 continue
23044 continue
      endif
      endif
      call fputc( 6, cnum(io))
      if(mod(length - io, 10) .eq. 0)then
      if(mod(length - io, 60) .eq. 0)then
      if(io .lt. length)then
      call fputc( 6, char(10))
      endif
      else
      call fputc( 6, " ")
      endif
      endif
23023 continue
23024 continue
      call fputc( 6, char(10))
23006 goto 23005
23007 continue
      end
      subroutine putdec(fd,n,w)
      character ch(79)
      integer itoc,i,n,nd,w,fd
      nd=itoc(n,ch,79)
      i=nd+1
23051 if(.not.(i.le.w))goto 23053
      call fputc(fd, " ")
23052 i=i+1
      goto 23051
23053 continue
      i=1
23054 if(.not.(i.le.nd))goto 23056
      call fputc(fd,ch(i))
23055 i=i+1
      goto 23054
23056 continue
      return
      end
      integer function ctoi(in,i)
      character in(1)
      character*10 digits
      integer index,d,i
      data digits/"0123456789"/
23057 if(in(i).eq. " ")then
      i=i+1
      goto 23057
      endif
23058 continue
      ctoi=0
23059 if(.not.(in(i).ne.char(0)))goto 23061
      d=index(digits,in(i))
      if(d.eq.0)then
      goto 23061
      endif
      ctoi=10*ctoi + d - 1
23060 i=i+1
      goto 23059
23061 continue
      return
      end
      integer function itoc(int,str,size)
      integer iabs, mod, d,i,int,intval,j,size
      character k, str(size), digits(10)
      data digits /"0","1","2","3","4","5","6","7","8","9"/
      intval=iabs(int)
      str(1)=char(0)
      i=1
23064 continue
      i=i+1
      d=mod(intval,10)
      str(i)=digits(d+1)
      intval=intval/10
23065 if(.not.(intval.eq.0.or.i.ge.size))goto 23064
23066 continue
      if(int.lt.0 .and. i.lt.size)then
      i=i+1
      str(i)="-"
      endif
      itoc=i-1
      j=1
23069 if(.not.(j.lt.i))goto 23071
      k=str(i)
      str(i)=str(j)
      str(j)=k
      i=i-1
23070 j=j+1
      goto 23069
23071 continue
      return
      end
